<?php defined("MAIN_DIR") or die("No direct access");

$banks_query = "select * from `bank` where `city_id` = '$_SESSION[city]' and `bank_id` in (select `bank_id` from `vote` group by `bank_id`)";
if (isset($_GET['letter']) && $_GET['letter'] != "")
{
	$_GET['letter'] = strip_tags($_GET['letter']);
	$_GET['letter'] = $_GET['letter'][0].$_GET['letter'][1];
	$banks_query .= " and `name` like '$_GET[letter]%'";
}
$banks_query .= " order by `bank_id`";

$limit = 2;
$banks_result = mysql_query($banks_query);
$count = mysql_num_rows($banks_result);
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$banks_query .= " limit $start_list,$limit";
$banks_result = mysql_query($banks_query);
$banks_count = mysql_num_rows($banks_result);

$head_title = "Отзывы клиентов банков ".$current_city['city_name_rod'];
$head_description = "Положительные и отрицательные отзывы о банках в ".$current_city['city_name_pred'];
$head_keywords = "отзывы клиентов банков ".mb_strtolower($current_city['city_name'],'utf-8');

require_once APP.HEADFILE;
?>
<script type="text/javascript" src="/files/js/bank_list.js"></script>
<h1>Отзывы о банках <?php echo $current_city['city_name_rod']; ?></h1>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td align="left" valign="top" class="banki_main_col"><?php
			if ($banks_count > 0)
			{
				?><div class="tips_search_block">
					<div class="banki_poisk">Поиск</div>
					<div class="banki_po_pervoi_bukve">по первой букве в названии банка</div>
					<div id="banki_alfavit"><?php
						$letters = array();
						$letter_res = mysql_query("select * from `bank` where `city_id` = '$_SESSION[city]' and `bank_id` in (select `bank_id` from `vote` group by `bank_id`)");
						while ($letter_row = mysql_fetch_array($letter_res))
						{
							$letter = $letter_row['name'][0].$letter_row['name'][1];
							if (!in_array($letter,$letters))
								$letters[] = $letter;
						}
						for ($i = 144; $i < 176; $i++)
						{
							if ($i == 170 || $i == 172 || $i == 153)
								continue;
							$letter = chr(208).chr($i);
							if (in_array($letter,$letters))
							{
								echo "<a href='?letter=".$letter."'";
								if (isset($_GET['letter']) && $_GET['letter'] == $letter)
									echo " style='font-weight:bold'";
								echo ">".$letter."</a> ";
							}
							else
								echo $letter." ";
						}
						if (isset($_GET['letter']) && $_GET['letter'] != "")
							echo "<a href='/$c_name/mentions/' style='letter-spacing:0px;'><sup>x</sup></a>";
					?></div>
					<div align="right">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="67%" align="left" id="tip_add">
									<a href="<?php echo "/$c_name";?>/mentions/voting/">Добавить отзыв о банке</a>
								</td>
								<td width="33%" align="right"><img src="/files/images/tips.png" width="241" height="46" /></td>
							</tr>
						</table>
					</div>
				</div><?php
			}
			?><div id="tips_table"><?php
			if ($banks_count > 0)
			{
				$i = 0;
				?><table width="98%" border="0" cellspacing="0" cellpadding="0"><?php
				while ($bank_row = mysql_fetch_array($banks_result))
				{
					$i++;
					$mention_res = mysql_query("select * from `vote` where `bank_id` = '$bank_row[bank_id]'");
					$neutral = $positive = $negative = 0; 
					while ($mention_row = mysql_fetch_array($mention_res))
					{
						switch($mention_row['mark'])
						{
							case 0: $neutral++; break;
							case 1: $positive++; break;
							case -1: $negative++; break;
						}
					}
					?><tr valign="middle">
						<td width="21" align="center" class="banki_table_item banki_table_number"><?php echo $i+($page-1)*$limit; ?> </td>
						<td width="443" align="left" class="banki_table_item">
							<a href="<?php echo "/$c_name";?>/banks/<?php echo $bank_row['link'].".html"; ?>" class="tips_link_bank"><?php
								echo $bank_row['full_name'];
							?></a>
						</td>
						<td width="89" align="center" class="banki_table_item">
							<a href="<?php echo "/$c_name";?>/mentions/lenta/?bank_id=<?php echo $bank_row['bank_id']?>" class="tips_link_black"><?php
								echo $neutral + $positive + $negative;
							?></a>
						</td>
						<td width="75" align="center" class="banki_table_item">
							<a href="<?php echo "/$c_name";?>/mentions/lenta/?bank_id=<?php echo $bank_row['bank_id']?>&mention=positive" class="tips_link_green"><?php
								echo $positive;
							?></a>
						</td>
						<td width="21" align="center" class="banki_table_item">
							<a href="<?php echo "/$c_name";?>/mentions/lenta/?bank_id=<?php echo $bank_row['bank_id']?>&mention=neutral" class="tips_link_grey"><?php
								echo $neutral;
							?></a>
						</td>
						<td width="80" align="center" class="banki_table_item">
							<a href="<?php echo "/$c_name";?>/mentions/lenta/?bank_id=<?php echo $bank_row['bank_id']?>&mention=negative" class="tips_link_red"><?php
								echo $negative;
							?></a>
						</td>
					</tr><?php
				}
				?></table><?php
			}
			else
				echo "<h3 style='color:#C6C6C6'>Отзывы о банках не найдены</h3>";
			?></div>
			<div id="oprosy_table">
				<?php require_once APP."pageskin.php"; ?>
			</div>
		</td>
		<td width="218" align="left" valign="top">
			<div id="inside_tips_lenta"><a href="<?php echo "/$c_name";?>/mentions/lenta/">Лента отзывов</a></div><?php
			require_once APP."rating_column.php";
			require_once APP."vacancy_column.php";
		?></td>
	</tr>
</table>
<div class="inside_block">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr valign='top'>
			<td width="344" class="inside_info"><?php
				require_once APP."bank_list.php";
				require_once APP."currency_rates.php";
			?></td>
			<td width="646"><?php
				$info = mysql_fetch_array(mysql_query("select * from `info` where `info_id` = '8' limit 1"));
				$text = getRichText($info['text']);
				echo "<h2>$info[header]</h2>";
				echo "<p>$text</p>";
			?></td>
		</tr>
	</table>
</div>
<?php require_once APP.FOOTERFILE; ?>